/*
 * SimplificationFunction.java
 *
 * Created on den 22 april 2007, 22:42
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package grex.fitnessfunctions.Classification;

import grex.GP;
import grex.Prediction;
import grex.fitnessfunctions.FitnessFunction;
import grex.fitnessfunctions.IFitnessFunction;
import grex.genes.GeneException;

import java.io.Serializable;
import java.util.Enumeration;

/**
 *
 * @author rik
 */
public class SimplificationFitness extends FitnessFunction implements IFitnessFunction, Serializable{
    
    /** Creates a new instance of SimplificationFunction */
    public SimplificationFitness() {
        super("Simplification");
    }
    
    @Override
    protected double calcPredictionError(Prediction prediction, double targetValue) {
       return prediction.getPrediction() == targetValue ? 0 : 1;
    }
    
    @Override
    protected double calcParismonyPressure(GP gp){
        return gp.getNrOfNodes()*0.1;
    }

    /*
       public double calcFitness(GP gp) throws GeneException {
        double trainFitness=0;               
        gp.train();    
        for(Prediction p:gp.getPcTrain().values())
            if(p.getPrediction()!=p.getTargetValue())
                trainFitness++;

        trainFitness=trainFitness/gp.getPcTrain().size();            
        return trainFitness*100 + gp.getLength()*0.01;
        //return trainFitness*100 -gp.getLength();
    }
     //*/
}
